#ifndef NETNATIVE_LOG_WRAPPER_H
#define NETNATIVE_LOG_WRAPPER_H

#include <string>
#include <memory>
#include <cstdio>
#include <cstring>

#ifndef NETMGRNATIVE_LOG_TAG
#define NETMGRNATIVE_LOG_TAG "NetsysNativeService"
#endif

#define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)

#define PRINT_NATIVE_LOG(op, fmt, ...)                                                       \
    do {                                                                                     \
        char original_message[1024];                                                         \
        char temp_message[1024];                                                             \
        memcpy(temp_message, fmt, sizeof(temp_message));                                      \
        char *src_ptr = temp_message;                                                        \
        char *dst_ptr = original_message;                                                    \
        while (*src_ptr) {                                                                   \
            if (strncmp(src_ptr, "{public}", strlen("{public}")) == 0) {                     \
                src_ptr += strlen("{public}");                                                \
            } else {                                                                         \
                *dst_ptr++ = *src_ptr++;                                                     \
            }                                                                                \
        }                                                                                    \
        *dst_ptr = '\0';                                                                     \
        printf("%s: [%s-(%s:%d)] ", #op, __FUNCTION__, FILENAME, __LINE__);  \
        printf(original_message, ##__VA_ARGS__);                                             \
        printf("\n");                                                                        \
    } while(0)


#define NETNATIVE_LOGD(fmt, ...) PRINT_NATIVE_LOG(Debug, fmt, ##__VA_ARGS__)
#define NETNATIVE_LOGE(fmt, ...) PRINT_NATIVE_LOG(Error, fmt, ##__VA_ARGS__)
#define NETNATIVE_LOGW(fmt, ...) PRINT_NATIVE_LOG(Warn, fmt, ##__VA_ARGS__)
#define NETNATIVE_LOGI(fmt, ...) PRINT_NATIVE_LOG(Info, fmt, ##__VA_ARGS__)
#define NETNATIVE_LOGF(fmt, ...) PRINT_NATIVE_LOG(Fatal, fmt, ##__VA_ARGS__)

#endif // NETNATIVE_LOG_WRAPPER_H 
